/*
#          .,:,,,                                        .::,,,::.          
#        .::::,,;;,                                  .,;;:,,....:i:         
#        :i,.::::,;i:.      ....,,:::::::::,....   .;i:,.  ......;i.        
#        :;..:::;::::i;,,:::;:,,,,,,,,,,..,.,,:::iri:. .,:irsr:,.;i.        
#        ;;..,::::;;;;ri,,,.                    ..,,:;s1s1ssrr;,.;r,        
#        :;. ,::;ii;:,     . ...................     .;iirri;;;,,;i,        
#        ,i. .;ri:.   ... ............................  .,,:;:,,,;i:        
#        :s,.;r:... ....................................... .::;::s;        
#        ,1r::. .............,,,.,,:,,........................,;iir;        
#        ,s;...........     ..::.,;:,,.          ...............,;1s        
#       :i,..,.              .,:,,::,.          .......... .......;1,       
#      ir,....:rrssr;:,       ,,.,::.     .r5S9989398G95hr;. ....,.:s,      
#     ;r,..,s9855513XHAG3i   .,,,,,,,.  ,S931,.,,.;s;s&BHHA8s.,..,..:r:     
#    :r;..rGGh,  :SAG;;G@BS:.,,,,,,,,,.r83:      hHH1sXMBHHHM3..,,,,.ir.    
#   ,si,.1GS,   sBMAAX&MBMB5,,,,,,:,,.:&8       3@HXHBMBHBBH#X,.,,,,,,rr    
#   ;1:,,SH:   .A@&&B#&8H#BS,,,,,,,,,.,5XS,     3@MHABM&59M#As..,,,,:,is,   
#  .rr,,,;9&1   hBHHBB&8AMGr,,,,,,,,,,,:h&&9s;   r9&BMHBHMB9:  . .,,,,;ri.  
#  :1:....:5&XSi;r8BMBHHA9r:,......,,,,:ii19GG88899XHHH&GSr.      ...,:rs.  
#  ;s.     .:sS8G8GG889hi.        ....,,:;:,.:irssrriii:,.        ...,,i1,  
#  ;1,         ..,....,,isssi;,        .,,.                      ....,.i1,  
#  ;h:               i9HHBMBBHAX9:         .                     ...,,,rs,  
#  ,1i..            :A#MBBBBMHB #  .r1,..        ,..;3BMBBBHBB#Bh.     ..                    ....,,,,,i1;   
#   :h;..       .,..;,1XBMMMMBXs,.,, .. :: ,.               ....,,,,,,ss.   
#    ih: ..    .;;;, ;;:s58A3i,..    ,. ,.:,,.             ...,,,,,:,s1,    
#    .s1,....   .,;sh,  ,iSAXs;.    ,.  ,,.i85            ...,,,,,,:i1;     
#     .rh: ...     rXG9XBBM#M#MHAX3hss13&&HHXr         .....,,,,,,,ih;      
#      .s5: .....    i598X&&A&AAAAAA&XG851r:       ........,,,,:,,sh;       
#      . ihr, ...  .         ..                    ........,,,,,;11:.       
#         ,s1i. ...  ..,,,..,,,.,,.,,.,..       ........,,.,,.;s5i.         
#          .:s1r,......................       ..............;shs,           
#          . .:shr:.  ....                 ..............,ishs.             
#              .,issr;,... ...........................,is1s;.               
#                 .,is1si;:,....................,:;ir1sr;,                  
#                    ..:isssssrrii;::::::;;iirsssssr;:..                    
#                         .,::iiirsssssssssrri;;:.
*/
package com.itheima.health.dao;

import com.itheima.health.pojo.Role;
import com.itheima.health.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Set;

/**
 * <dl>
 * <dd>描述: ~ UserMapper</dd>
 * <dd>创建时间：  11:49 2021/2/23</dd>
 * <dd>创建人： guodong</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author         Version     Description
 * ------------------------------------------------------------------
 * 2021/2/23      guodong         1.0        1.0 Version
 * </pre>
 * </dl>
 */
public interface UserMapper extends Mapper<User> { //注意mapper是tk包下的

	/**
	 * @Author: guodong
	 * @Date: 11:49 2021/2/23
	 * @Parms [username]
	 * @ReturnType: com.itheima.health.pojo.User
	 * @Description: 根据用户名查询用户
	 */
	//User findUserByName(@Param("username") String username);
	@Select("SELECT t3.`name` FROM t_user t1\n" +
			"JOIN \n" +
			"t_user_role t2\n" +
			"ON t1.`id`=t2.`user_id`\n" +
			"JOIN\n" +
			"t_role t3\n" +
			"ON\n" +
			"t2.`role_id`=t3.`id`")
	Set<Role> getRoles();

	/**
	 * @Author: wty
	 * @Date: 17:06 2021/3/12
	 * @Parms [id]
	 * @ReturnType: com.itheima.health.entity.Result
	 * @Description: 根据用户id查询其->角色 ->权限->菜单

	 */
	@Select("SELECT t5.`id`  FROM\n" +
			"t_user t1\n" +
			"JOIN\n" +
			"t_user_role t2\n" +
			"ON \n" +
			"t1.`id`=t2.`user_id`\n" +
			"JOIN\n" +
			"t_role t3 \n" +
			"ON\n" +
			"t3.`id`=t2.`role_id`\n" +
			"JOIN\n" +
			"t_role_menu t4\n" +
			"ON\n" +
			"t4.`role_id` =t3.`id`\n" +
			"JOIN\n" +
			"t_menu t5\n" +
			"ON\n" +
			"t5.`id`=t4.`menu_id`\n" +
			"WHERE \n" +
			"t1.`id`=#{id}")
	List<Integer> findMenuIdsById(@Param("id") Integer id);
}
